From: Andy Chiang Date: Wed, 15 Oct 2025 17:48:55 +0000 (+0700) Subject: luci-mod-dashboard: use localized time X-Git-Url: http://git.openwrt.org/%22https:/collectd.org//%22http:/www.crowdsec.net/%22/%22https:/collectd.org/%22http:/www.crowdsec.net/%22?a=commitdiff_plain;h=71ea35fc7f41e8b1c6c02e0bcc8d8bfcba3bde7f;p=project%2Fluci.git luci-mod-dashboard: use localized time use localized time Signed-off-by: Andy Chiang --- diff --git a/modules/luci-mod-dashboard/htdocs/luci-static/resources/view/dashboard/include/10_router.js b/modules/luci-mod-dashboard/htdocs/luci-static/resources/view/dashboard/include/10_router.js index d97fc9cadf..8005ff6744 100644 --- a/modules/luci-mod-dashboard/htdocs/luci-static/resources/view/dashboard/include/10_router.js +++ b/modules/luci-mod-dashboard/htdocs/luci-static/resources/view/dashboard/include/10_router.js @@ -3,6 +3,7 @@ 'require fs'; 'require rpc'; 'require network'; +'require uci'; var callSystemBoard = rpc.declare({ object: 'system', @@ -14,6 +15,12 @@ var callSystemInfo = rpc.declare({ method: 'info' }); +var callGetUnixtime = rpc.declare({ + object: 'luci', + method: 'getUnixtime', + expect: { result: 0 } +}); + return baseclass.extend({ params: [], @@ -23,7 +30,9 @@ return baseclass.extend({ network.getWANNetworks(), network.getWAN6Networks(), L.resolveDefault(callSystemBoard(), {}), - L.resolveDefault(callSystemInfo(), {}) + L.resolveDefault(callSystemInfo(), {}), + L.resolveDefault(callGetUnixtime(), 0), + uci.load('system') ]); }, @@ -298,20 +307,22 @@ return baseclass.extend({ const boardinfo = data[2]; const systeminfo = data[3]; + const unixtime = data[4]; let datestr = null; - if (systeminfo.localtime) { - const date = new Date(systeminfo.localtime * 1000); - - datestr = '%04d-%02d-%02d %02d:%02d:%02d'.format( - date.getUTCFullYear(), - date.getUTCMonth() + 1, - date.getUTCDate(), - date.getUTCHours(), - date.getUTCMinutes(), - date.getUTCSeconds() - ); + if (unixtime) { + const date = new Date(unixtime * 1000); + const zn = uci.get('system', '@system[0]', 'zonename')?.replaceAll(' ', '_') || 'UTC'; + const ts = uci.get('system', '@system[0]', 'clock_timestyle'); + const hc = uci.get('system', '@system[0]', 'clock_hourcycle'); + + datestr = new Intl.DateTimeFormat(undefined, { + dateStyle: 'medium', + timeStyle: (ts == 0) ? 'long' : 'full', + hourCycle: hc, + timeZone: zn + }).format(date); } this.params.router = { diff --git a/modules/luci-mod-dashboard/root/usr/share/rpcd/acl.d/luci-mod-dashboard.json b/modules/luci-mod-dashboard/root/usr/share/rpcd/acl.d/luci-mod-dashboard.json index 1f331e7b4b..023122a3c2 100644 --- a/modules/luci-mod-dashboard/root/usr/share/rpcd/acl.d/luci-mod-dashboard.json +++ b/modules/luci-mod-dashboard/root/usr/share/rpcd/acl.d/luci-mod-dashboard.json @@ -16,6 +16,7 @@ }, "ubus": { "file": [ "list", "read" ], + "luci": [ "getUnixtime" ], "system": [ "board", "info" ] } }